package com.insyte.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.insyte.R;
import com.insyte.model.User;

import java.util.List;

/**
 * Created by T430 on 7/14/2015.
 */
public class ResultSearchAdapter extends ArrayAdapter<User> {
    private Context context;
    private int layout_id;
    private List<User> users;
    private LayoutInflater inflater;
    private Holder holder;

    public ResultSearchAdapter(Context context, int layout_id, List<User> users) {
        super(context, layout_id, users);
        this.context = context;
        this.layout_id = layout_id;
        this.users = users;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            holder = new Holder();
            convertView = inflater.inflate(layout_id, parent, false);
            holder.tv_job = (TextView) convertView.findViewById(R.id.tv_job);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_height = (TextView) convertView.findViewById(R.id.tv_height);
            holder.tv_weight = (TextView) convertView.findViewById(R.id.tv_weight);
            holder.tv_description = (TextView) convertView.findViewById(R.id.tv_description);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        return convertView;
    }

    private static class Holder {
        TextView tv_job, tv_name, tv_height, tv_weight, tv_description;
    }
}
